﻿965.单值二叉树
bool isUnivalTree(struct TreeNode* root) {
    if (root == NULL)
    {
        return true;
    }
    if (root->left && root->val != root->left->val)
    {
        return false;
    }
    if (root->right && root->val != root->right->val)
    {
        return false;
    }
    return isUnivalTree(root->left) && isUnivalTree(root->right);
}

100.相同的树
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
    {
        return true;
    }
    if (p == NULL || q == NULL)
    {
        return false;
    }
    if (p->val != q->val)
    {
        return false;
    }
    return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}

101.对称二叉树
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
    {
        return true;
    }
    if (p == NULL || q == NULL)
    {
        return false;
    }
    if (p->val != q->val)
    {
        return false;
    }
    return isSameTree(p->left, q->right) && isSameTree(p->right, q->left);
}
bool isSymmetric(struct TreeNode* root) {
    if (root == NULL)
    {
        return true;
    }
    return isSameTree(root->left, root->right);
}

572.另一棵树的子树
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
    {
        return true;
    }
    if (p == NULL || q == NULL)
    {
        return false;
    }
    if (p->val != q->val)
    {
        return false;
    }
    return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if (root == NULL)
    {
        return false;
    }
    if (isSameTree(root, subRoot))
    {
        return true;
    }
    return isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);
}

144.二叉树的前序遍历
int Treesize(struct TreeNode* root) {
    if (root == NULL)
    {
        return 0;
    }
    return 1 + Treesize(root->right) + Treesize(root->left);
}
void _preorderTraversal(struct TreeNode* root, int* arr, int* pn) {
    if (root == NULL)
    {
        return;
    }
    arr[(*pn)++] = root->val;
    _preorderTraversal(root->left, arr, pn);
    _preorderTraversal(root->right, arr, pn);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int size = Treesize(root);
    *returnSize = size;
    int* ans = (int*)malloc(sizeof(int) * size);
    int n = 0;
    _preorderTraversal(root, ans, &n);
    return ans;
}

94.二叉树的中序遍历
int Treesize(struct TreeNode* root) {
    if (root == NULL) {
        return 0;
    }
    return 1 + Treesize(root->right) + Treesize(root->left);
}
void _inorderTraversal(struct TreeNode* root, int* arr, int* pn) {
    if (root == NULL) {
        return;
    }
    _inorderTraversal(root->left, arr, pn);
    arr[(*pn)++] = root->val;
    _inorderTraversal(root->right, arr, pn);
}
int* inorderTraversal(struct TreeNode* root, int* returnSize) {
    int size = Treesize(root);
    *returnSize = size;
    int* ans = (int*)malloc(sizeof(int) * size);
    int n = 0;
    _inorderTraversal(root, ans, &n);
    return ans;
}

145.二叉树的后序遍历
int Treesize(struct TreeNode* root) {
    if (root == NULL) {
        return 0;
    }
    return 1 + Treesize(root->right) + Treesize(root->left);
}
void _postorderTraversal(struct TreeNode* root, int* arr, int* pn) {
    if (root == NULL) {
        return;
    }
    _postorderTraversal(root->left, arr, pn);
    _postorderTraversal(root->right, arr, pn);
    arr[(*pn)++] = root->val;
}
int* postorderTraversal(struct TreeNode* root, int* returnSize) {
    int size = Treesize(root);
    *returnSize = size;
    int* ans = (int*)malloc(sizeof(int) * size);
    int n = 0;
    _postorderTraversal(root, ans, &n);
    return ans;
}

KY11 二叉树遍历（牛客网）
#include <stdio.h>
#include<stdlib.h>
typedef struct TreeNode {
    char val;
    struct TreeNode* left;
    struct TreeNode* right;
} TreeNode;
TreeNode* BuyTreeNode(char x) {
    TreeNode* newnode = (TreeNode*)malloc(sizeof(TreeNode));
    newnode->val = x;
    newnode->right = NULL;
    newnode->left = NULL;
    return newnode;
}
TreeNode* CreatTree(char* arr, int* pi) {
    if (arr[*pi] == '#') {
        (*pi)++;
        return NULL;
    }
    TreeNode* newnode = BuyTreeNode(arr[(*pi)++]);
    newnode->left = CreatTree(arr, pi);
    newnode->right = CreatTree(arr, pi);
    return newnode;
}
void inorderTraversal(TreeNode* root) {
    if (root == NULL) {
        return;
    }
    inorderTraversal(root->left);
    printf("%c ", root->val);
    inorderTraversal(root->right);
}
int main() {
    char arr[100];
    scanf("%s", arr);

    int i = 0;
    TreeNode* ans = CreatTree(arr, &i);

    inorderTraversal(ans);
    return 0;
}